// JavaScript Document
var objPool=new Array();
var outDiv=new Array();

function callAHAH(url, pageElement, callMessage){
	document.getElementById(pageElement).innerHTML = callMessage;
	var req_i = getInstance(pageElement);
	objPool[req_i].onreadystatechange = function(){responseAHAH(req_i);};//调用输出函数，显示处理结果
	objPool[req_i].open("GET",url,true);
	objPool[req_i].send(null);
}
function responseAHAH(req_i){
	var output = '';
    if (objPool[req_i].readyState == 4) {
        if(objPool[req_i].status == 200) {
//			alert(objPool.length+"obj num:"+req_i);
            if(outDiv[req_i]!=null & outDiv[req_i].indexOf("null")==-1){
                var output = objPool[req_i].responseText;
                document.getElementById(outDiv[req_i]).innerHTML = output;
//                creatJS(output);
            }
        } else{
                document.getElementById(outDiv[req_i]).innerHTML = "error";//alert("加载出错！给您带来不便，敬请谅解！");
		}
    }
}

function  getInstance(_pageElement){
	for (var i = 0; i < this.objPool.length; i ++)
	{
		if (this.objPool[i].readyState == 0 || this.objPool[i].readyState == 4){
			outDiv[i]=_pageElement;
			return i;
		}
	}
	// IE5中不支持push方法
	this.outDiv[this.objPool.length] = _pageElement;
	this.objPool[this.objPool.length] = this.createReq();
	
	return this.outDiv.length-1;
}

function createReq(){
	//alert("new XML");
	if (window.XMLHttpRequest){//Firefor
		var objXMLHttp = new XMLHttpRequest();
	} else {// Internet Explorer
		var MSXML = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
		for(var n = 0; n < MSXML.length; n ++)
		{
			try{
				var objXMLHttp = new ActiveXObject(MSXML[n]);        
				break;
			}catch(e){ }
		}
	 }
	// mozilla某些版本没有readyState属性
	if (objXMLHttp.readyState == null){
		objXMLHttp.readyState = 0;
		objXMLHttp.addEventListener("load", function (){
			objXMLHttp.readyState = 4;
			if (typeof objXMLHttp.onreadystatechange == "function"){
				objXMLHttp.onreadystatechange();
			}
		},  false);
	}
	return objXMLHttp;
}

function creatJS(ajaxLoadedData){
	 // 第一步：匹配加载的页面中是否含有js   
	var regDetectJs = /<script(.|\n)*?>(.|\n|\r\n)*?<\/script>/ig;
	var jsContained = ajaxLoadedData.match(regDetectJs);

	// 第二步：如果包含js，则一段一段的取出js再加载执行   
	if (jsContained) {
		// 分段取出js正则   
		var regGetJS = /<script(.|\n)*?>((.|\n|\r\n)*)?<\/script>/im;

		// 按顺序分段执行js   
		var jsNums = jsContained.length;
		for ( var i = 0; i < jsNums; i++) {
			var jsSection = jsContained[i].match(regGetJS);

			if (jsSection[2]) {
				
				if (window.execScript) {
					// 给IE的特殊待遇   
					window.execScript(jsSection[2]);
				} else {
					// 给其他大部分浏览器用的   
					window.eval(jsSection[2]);
				}
			}
		}
	} 
}